package com.ibeetl.cms.service;


import com.ibeetl.cms.dao.XxdItemDao;
import com.ibeetl.cms.entity.XxdItem;



import com.ibeetl.admin.core.service.CoreBaseService;
import com.ibeetl.admin.core.util.PlatformException;
import org.beetl.sql.core.engine.PageQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;






/**
 * XxdItem Service
 */

@Service
@Transactional
public class XxdItemService extends CoreBaseService<XxdItem>{

    @Autowired private XxdItemDao xxdItemDao;

    public PageQuery<XxdItem>queryByCondition(PageQuery query){
        PageQuery ret =  xxdItemDao.queryByCondition(query);
        queryListAfter(ret.getList());
        return ret;
    }

    public void batchDelXxdItem(List<Long> ids){
        try {
            xxdItemDao.batchDelXxdItemByIds(ids);
        } catch (Exception e) {
            throw new PlatformException("批量删除XxdItem失败", e);
        }
    }

    @Override
    public boolean updateTemplate(XxdItem model) {
        return sqlManager.updateTemplateById(model) > 0;
    }

    @Transactional(rollbackFor = Exception.class)
    public void batchInsert(List<XxdItem> list) throws Exception{
        for (XxdItem item : list) {
            if(sqlManager.insertTemplate(item) == 0){
                throw new PlatformException("导入失败");
            }
        }
    }
}